<template>
  <div>
    <el-col :span="18">
      <el-input v-model="keyword" placeholder="input"></el-input>
    </el-col>
    <el-col :span="5">
      <el-button icon="el-icon-search" circle @click="searchData"></el-button>
    </el-col>
  </div>
</template>

<script>
import Global from "../js/global";
import eventBus from "../js/eventBus";

export default {
  name: "Search",
  data() {
    return {
      keyword: ''
    };
  },

  methods: {
    searchData() {
      let keyword = this.keyword;
      if (keyword === '') {
        this.$message.error("请输入要搜索文件的关键字");
        return;
      }

      var rule = /[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~！@#￥%……&*（）——\-+={}|《》？：“”【】、；‘'，。、]/im;
      if (keyword === "" || rule.test(keyword)) {
        this.$message.error("禁止输入特殊符号");
        return;
      }
      const that = this
      this.axios({
        url: Global.SERVER_ADDRESS + "/search/s/" + keyword,
        params: {
          token: that.$cookies.get("TOKEN")
        }
      }).then(function (rs) {
        if (rs.data.code === '200') {
          eventBus.$emit("searData", JSON.parse(rs.data.msg));
        } else {
          that.$message.error("查找错误");
        }
      }).catch(function (error) {
        console.log(error);
        that.$message.error("500 错误");
      });
    },
  }
}
</script>

<style scoped>

</style>
